/*
 * @Date: 2023-03-22 16:35:49
 * @LastEditors: Chuying
 * @LastEditTime: 2023-03-22 16:36:49
 * @Description: 
 */
import { Module } from '@nestjs/common';
import { FileService } from './file.service';
import { FileController } from './file.controller';

import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname, join } from 'path';

@Module({
  imports: [
    //MulterModule register注册存放图片的目录
    MulterModule.register({
      //diskStorage 设置存放目录
      storage: diskStorage({
        // __dirname 当前文件目录
        // process.cwd() 执行 node  xxx.js  时候 所在的当前路径
        destination: join(process.cwd(), '/public/images'),
        filename: (_, file, callback) => {
          // extname 用来读取文件后缀
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
  ],
  controllers: [FileController],
  providers: [FileService],
})
export class FileModule {}
